package test;

import java.awt.Color;
import java.awt.Point;
import java.util.Vector;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.appearances.Circle;
import com.uqbar.vainilla.appearances.Rectangle;

public class BolitaLocaComponent extends GameComponent<ScenaTest> {

	private int speed;
	private int diameter;
	private Point direction;
	
	public void setSpeed(int speed) {
		this.speed = speed;
	}

	public int getSpeed() {
		return speed;
	}
	public void setDirection(Point direction) {
		this.direction = direction;
	}

	public Point getDirection() {
		return direction;
	}
	
	public BolitaLocaComponent(Color color, int diameter, double x, double y) {
		super(new Circle(color, diameter), x, y);
		this.speed = 200;
		this.diameter = diameter;
		this.direction = (new Point(1, 1));
	}

	public void update(DeltaState deltaState) {
		super.update(deltaState);
		double intensity = deltaState.getDelta() * this.getSpeed();
		
		this.move(intensity * this.getDirection().x, intensity * this.getDirection().y);
		
		if (this.crashedToX()){
			this.updateDirection(new Point(-1, 1));
		}
		if (this.crashedToY()){
			this.updateDirection(new Point(1, -1));
		}
	}
	public boolean crashedToX(){
		return (this.getX() < 0 | this.getX() >  this.getGame().getDisplayWidth() - this.diameter);
			
	}
	public boolean crashedToY(){
		return (this.getY() < 0 | this.getY() >  this.getGame().getDisplayHeight() - this.diameter);
			
	}
	public void updateDirection(Point scale){
		this.setDirection(new Point(this.getDirection().x * scale.x, this.getDirection().y * scale.y));
	}


}
